<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>云校通-家长-选班</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<body ontouchstart>
	<div class="weui_tab tab-bottom">
		<div class="weui-header bg-blue"> 
	  		<div class="weui-header-left"><a onclick="back()" href="javascript:;" class="icon icon-109 f-white">返回</a></div>
	    	<h1 class="weui-header-title">选修课详情</h1>
	    </div>
	    <div class="weui_tab_bd">
	    	<c:if test="${detail.attachList != null}">
	    		<div class="weui-weixin-img" style="margin-bottom: -10px;"><!--图片开始-->
			    	<img src="${config.imgUrl }${detail.mainImg }" class="weixin">
			    </div>
	    	</c:if>
		    <div class="weui_cells mt0">
			    <div class="weui_cell">
			        <div class="weui_cell_bd weui_cell_primary">${detail.courseName }</div>
			        <c:if test="${detail.limitNum != null }">
			        	<div class="weui_cell_ft">${detail.studentSignCount}/${detail.limitNum }</div>
			        </c:if>
			    </div>
			    <div class="weui_cells_title">授课老师: ${detail.classTeacher }</div>
			    <div class="weui_cells_title">上课地点: ${detail.classAddr }</div>
			    <c:if test="${detail.rainAddr != null && !empty detail.rainAddr}">
			   		<div class="weui_cells_title">备用地点: ${detail.rainAddr }</div>
				</c:if>
				<c:if test="${signView != null }">
					<div class="weui_cells_title r-red">已报名课程: ${signView.courseName }</div>
				</c:if>
			</div>
		    <div class="weui-weixin-content p10" style="padding-bottom: 20px;">
		        <p>${detail.courseDesc }</p>
		        <c:forEach var="itm" items="${detail.attachList }">
		        	<p><img src="${config.imgUrl }${itm.attachmentUrl }" class="weixin"></p>
		        </c:forEach>
		    </div>
		    <a href="javascript:;" id="sign" class="footer_btn"></a>
		 </div>
	</div>
</body>
<script>
	var oldCourseId = emptyToNull("${signView.courseId}");
    $(function(){
    	if(oldCourseId == null) {
    		$("#sign").html("立即报名");
    	}else {
    		$("#sign").html("立即调班");
    	}
    	$("#sign").click(function() {
    		if(oldCourseId == null) {
    			signSubmit();
    		}else {
    			changeSubmit();
    		}
    	})
    })
    function signSubmit() {
    	$.confirm("确定提交结果吗?", "确认选班?", function() {
	    	var studentId = queryStringByName("xbsid");
	    	if(studentId == null) return;
	    	$.ajax({
		   		url: basePath + "/xs/kccs/course/signSubmit",
		   		type: 'POST',
		   		dataType : "json",
		   		data: {
		   			studentId: studentId,
		   			courseId: "${detail.id}",
		   		},
		   		success: function(data) {
		   			if (data.code == '000') {
		   				$.toast("提交成功");
		   				setTimeout(function() {
		   					window.location.href = basePath + "/xs/kccs/course?sid=${user.parent.studentId}";
		   				}, 1000);
		   			}else {
		   				$.alert(data.msg);
		   			}
		   		},
		   		error: function(data) {
		   			$.toptips("系统异常,请联系管理员");
		   		}
		   });
    	}, function() {
            //取消操作
        });
    }
    function changeSubmit() {
    	$.confirm("确定提交结果吗?", "确认调班?", function() {
    		var studentId = queryStringByName("xbsid");
        	if(studentId == null) return;
        	$.ajax({
    	   		url: basePath + "/xs/kccs/course/changeSubmit",
    	   		type: 'POST',
    	   		dataType : "json",
    	   		data: {
    	   			studentId: studentId,
    	   			oldCourseId: "${signView.courseId}",
    	   			newCourseId: "${detail.id}",
    	   		},
    	   		success: function(data) {
    	   			if (data.code == '000') {
    	   				$.alert("提交成功！请耐心等候班主任审批", "");
    	   				setTimeout(function() {
    	   					window.location.href = basePath + "/xs/kccs/course?sid=${user.parent.studentId}";
    	   				}, 2000);
    	   			}else {
    	   				$.alert(data.msg, "");
    	   			}
    	   		},
    	   		error: function(data) {
    	   			$.toptips("系统异常,请联系管理员");
    	   		}
    	   });
        }, function() {
          //取消操作
        });
    }
    
</script>
</html>